package com.itheima.health.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.health.mapper.UserMapper;
import com.itheima.health.pojo.Permission;
import com.itheima.health.pojo.User;
import com.itheima.health.service.UserService;
import com.itheima.health.vo.RoleVO;
import com.itheima.health.vo.UserVO;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@SuppressWarnings("ALL")
/**
 * @Description :
 * @author     :LD
 */
@Service
@Transactional
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Override
    public UserVO findUserByUsername(String username) {
        //根据用户名查询用户信息
        UserVO userVO = baseMapper.findUserByUsername(username);
        if (userVO==null) return null;
        //根据用户id查询角色
        List<RoleVO> roleVOList = baseMapper.findRolesByUid(userVO.getId());
        if (roleVOList==null||roleVOList.size()==0) return userVO;
        for (RoleVO role : roleVOList) {
            //根据角色id查询权限信息
            List<Permission> permissionList = baseMapper.findPermssionsByRoleId(role.getId());
            role.setPermissionsList(permissionList);
        }
        userVO.setRoleVOList(roleVOList);
        return userVO;
    }
}
